package com.hc.Controller;


import com.hc.Feign.IMemberFeigns;
import com.hc.feign.IMemberFeign;
import com.hc.pojo.Meber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@RestController
    public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @Resource
    private IMemberFeign iMemberFeign;

    @Autowired
    private IMemberFeigns iMemberFeigns;

    @RequestMapping("/getOrder")
    public String getOrder(){
        String foObject=restTemplate.getForObject("http://APP-HWX-MEMBER/getMenber",String.class);
        return "订单调用会员系统："+foObject;
    }

    @RequestMapping("/getOrderFeign")
    public String getOrderFeign(){

        return "订单调用会员系统："+iMemberFeigns.getMenber();
    }

    @RequestMapping("/getMemberList")
    public List<Meber> getMemberList(){

        return iMemberFeign.getMenberList();
    }

    @RequestMapping("/getMenberById")
    public  String getMenberById(Integer id){
        System.out.println("-------------------"+id+"------------------------");
      return   iMemberFeign.getMenberById(id);
    }

    /**
     * 服务熔断演示方法
     * @param id
     * @return
     */
    @RequestMapping("/getMenberById2")
    public  Meber getMenberById2( Integer id){
        return iMemberFeign.getMenberById2(id);
    }

    @RequestMapping("/addMeber")
    public  void addMenber( Meber meber){
        System.out.println("-------------------"+meber+"------------------------");
        iMemberFeign.addMeber(meber);
    }
}
